<?php
session_start();
if (isset($_POST['openid']) && !empty($_POST['openid']) && isset($_POST['id'])){
    include '../c/config.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    $openid=addslashes(trim($_POST['openid']));
    $id=addslashes(trim($_POST['id']));
    $type=addslashes(trim($_POST['t']));

    $query=$mysqli->query("SELECT qiuid,openid FROM joinqiu where id='".$id."' limit 0,1 ");
    if($query->num_rows>0){
        $getJoin=$query->fetch_assoc();
        $query=$mysqli->query("SELECT id FROM qdui where id='".$getJoin['qiuid']."' and openid='".$openid."'  limit 0,1 ");
        if($query->num_rows>0){
            $isapply=2;
            if('yes' == $type){
                $isapply=1;
                $mysqli->query("update joinqiu set isapply=".$isapply." where id='".$id."' ");
                //通知球员
                $mysqli->query("insert into message(myid,fromid,type,createtime) values('".$getJoin['openid']."','".$openid."','2','".date("Y-m-d H:i:s")."')  ");
            }else{
                $mysqli->query("insert into message(myid,fromid,type,createtime) values('".$getJoin['openid']."','".$openid."','3','".date("Y-m-d H:i:s")."')  ");
                $mysqli->query("delete from joinqiu where id='".$id."' ");
            }
            
        }
    }
    $mysqli->close();
    
    echo json_encode(array('s'=>'y'));
}

